<?php
namespace Admin\Controller;
use Think\Controller;
class AdminController extends Controller {
    protected function _initialize()
    {
        // 登录报错
        if(session('lh_uid') < 1){
            //没有session
            $this->error('请先登录',U('Login/index'));
        }
        //权限判断
        $urls[] = 'Index/index';//后台首页
        foreach (session('lh_privilege') as $v){
            $urls[] = $v['url'];
        }

        $wh['url'] = CONTROLLER_NAME.'/'.ACTION_NAME;
        $one = M('Menu')->field('id')->where($wh)->find();//查不到 默认给他有权限
//        var_dump($one);exit;
        if($one){
            if(!in_array_case(CONTROLLER_NAME.'/'.ACTION_NAME,$urls)){
                $this->error("没有此权限，请联系管理员",U('Index/index'));
            }
        }


        //菜单栏输出
        $menu = get_category(session('lh_privilege'),1);//伪树形数组



        //打开拥有全部菜单
/*        $menu = M('Menu')->order('pid,sort,u_time desc,id desc')->select();
        $menu = get_category($menu,1);//伪树形数组*/

        $this->assign('menu',$menu);// 赋值数据集
    }
}
?>